package com.atguigu.spring.aop.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class AroundAspect {
    @Pointcut("args(int, int)")
    public void pointCut() {
    }

    @Around("pointCut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        Object[] args = joinPoint.getArgs();
        System.out.println("这里写环绕-前置");
        Object proceed = null;
        try {
            proceed = joinPoint.proceed(args);

            System.out.println("这里写环绕-返回");
        } catch (Exception e) {

            System.out.println("这里写环绕-异常"+e.getMessage());
            throw e;
        } finally {
            System.out.println("这里写环绕-后置");
        }
        return proceed;
    }
}
